package com.gkoudai.open.platform.deserializer;


import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.gkoudai.open.platform.common.CategoryCommon;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author wangqi
 * @date 2025-05-12 14:53
 */
public class NewsTypeEnumListDeserializer extends JsonDeserializer<List<CategoryCommon.NewsTypeEnum>> {

    @Override
    public List<CategoryCommon.NewsTypeEnum> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        String typeCodeStr = p.getText();
        List<String> typeCodeList = Arrays.asList(typeCodeStr.split(","));
        return typeCodeList.stream()
                .map(CategoryCommon.NewsTypeEnum::fromCode)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
    }
}